﻿<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="Bookmark" href="/favicon.ico">
    <link rel="Shortcut Icon" href="/favicon.ico" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="../lib/html5shiv.js"></script>
    <script type="text/javascript" src="../lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="../static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="../lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/style.css" />
    <!--[if IE 6]>
    <script type="text/javascript" src="../lib/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <!--/meta 作为公共模版分离出去-->

    <title>代码版本监听信息</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <style>
        .tableclone {
            border-collapse: separate;
            border-spacing: 1px;
            background-color: #ddd;
            margin-bottom: 30px;
        }

        .tableclone td {
            background-color: white;
        }

        .tableclone th {
            background-color: #a5c8e2;
            font-weight: bold;
            text-align: center;
            color:#333;
            font-size: 14px;
        }

        .tableclone input[type=text] {
            line-height: 30px;
            box-sizing: border-box;
            padding-left: 8px;
            outline: none;
            border: 0;
            width: 100%;
        }
    </style>
</head>

<body>
    <article class="page-container">
        <form class="form form-horizontal" id="form-article-add">

            <div class="row cl" style="display:none;">
                <label class="form-label"><span class="c-red">*</span>ID标识：</label>
                <div class="formControls">
                    <input type="text" class="input-text" value="0" placeholder="" name="id" readonly>
                </div>
            </div>

            <div class="row cl">
                <label class="form-label">[外]哪个服务</label>
                <div class="formControls">
                    <select name="serviceId">
                        <option value="0">待选择</option>
                    </select>
                </div>
            </div>


            <div class="row cl">
                <label class="form-label">克隆编译命令</label>
                <div class="formControls">
                    <textarea name="commandClone"
                        placeholder="在此键入克隆和编译的命令&#13;&#10;命令间是独立的,一条命令一行，所以路径啥的要写全路径!!! &#13;&#10;开头的一行表示注释 &#13;&#10;示例(请先在这个服务器上执行签出命令以便确认账号等信息)&#13;&#10;#删除旧的代码，这一步骤要看情况&#13;&#10;rm -rf /spider/source/projectcode/&#13;&#10;#把代码从远端签出&#13;&#10;svn checkout svn://192.168.1.5:12300/svnrepos --username=user --password=123456 /spider/source/projectcode/&#13;&#10;#把代码从git远端克隆出来&#13;&#10;git clone ssh://git@192.168.1.5:15892/gitlab-instance-f41b7b1f/projectname.git -b branchname /spider/source/projectcode/&#13;&#10;#构建并发布&#13;&#10;dotnet publish -s /spider/source/projectcode/ -c release -r linux-x64 --self-contained false -o /spider/publish/projectcode/&#13;&#10;可以执行一些配置信息等的复制"></textarea>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label">源码管理方式</label>
                <div class="formControls">
                    <select name="codeType">
                        <option value="git" selected>Git</option>
                        <option value="svn" selected>Svn</option>
                    </select>
                </div>
            </div>

            <div class="row cl">
                <label class="form-label">验证密钥</label>
                <div class="formControls">
                    <input type="text" class="input-text" value="" placeholder="验证密钥" name="pushToken">
                    <input type="button" class="btnguid" value="生成" onclick="_funcrandomstr(this);">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label">[外]私有仓储</label>
                <div class="formControls">
                    <select name="storeId">
                        <option value="0">待选择</option>
                    </select>
                </div>
            </div>

            <div class="row cl">
                <label class="form-label">升级规则</label>
                <script type="text/html" id="templatecloneconfigitem">
                    <tr class="text-c">
                        <td><input class="inputenable" type="checkbox" [isEnableStr]></td>
                        <td class="inputmodel">[modelCode]</td>
                        <td><input type="text" class="inputbranch" placeholder="git的分支名称" maxlength="32" value="[branchName]"></td>
                        <td><input type="text" class="inputprefix" maxlength="16" placeholder="最后一行备注的开头字母" value="[prefixStr]"></td>
                    </tr>
                </script>
                <div class="formControls">
                    <table class="tableclone">
                        <thead>
                            <tr class="text-c">
                                <th width="50">状态</th>
                                <th>环境</th>
                                <th>分支</th>
                                <th>关键字</th>
                            </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                </div>
            </div>
            <div class="row cl">
                <div class="rowbtn">
                    <button onClick="_funcAdd();" class="btn btn-primary radius" type="button">保存</button>
                </div>
            </div>
        </form>
    </article>

    <!--_footer 作为公共模版分离出去-->
    <script type="text/javascript" src="../lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="../lib/layer/2.4/layer.js"></script>
    <script type="text/javascript" src="../static/h-ui/js/H-ui.min.js"></script>
    <script type="text/javascript" src="../static/h-ui.admin/js/H-ui.admin.js"></script>
    <!--/_footer /作为公共模版分离出去-->
    <!--请在下方写此页面业务相关的脚本-->
    <script src="../lib/api.js"></script>


    <script type="text/javascript">

        var iseditemodel = false;
        $(function () {

            /*
            &#13;&#10;在此键入克隆和编译的命令&#13;&#10;命令间是独立的,一条命令一行，所以路径啥的要写全路径!!! &#13;&#10;开头的一行表示注释 &#13;&#10;示例(请先在这个服务器上执行签出命令以便确认账号等信息)&#13;&#10;#删除旧的代码，这一步骤要看情况&#13;&#10;rm -rf /spider/source/projectcode/&#13;&#10;#把代码从远端签出&#13;&#10;svn checkout svn://192.168.1.5:12300/svnrepos --username=user --password=123456 /spider/source/projectcode/&#13;&#10;#把代码从git远端克隆出来&#13;&#10;git clone ssh://git@192.168.1.5:15892/gitlab-instance-f41b7b1f/projectname.git -b branchname /spider/source/projectcode/&#13;&#10;#构建并发布&#13;&#10;dotnet publish -s /spider/source/projectcode/ -c release -r linux-x64 --self-contained false -o /spider/publish/projectcode/&#13;&#10;可以执行一些配置信息等的复制
*/

            //获取参数中的ID
            var _id = 0;

            var uidstr = _apigetquery("id");
            if (uidstr != null) {
                _id = parseInt(uidstr);
                iseditemodel = true;
                if (_id == 0) {
                    iseditemodel = false;
                }
            } else {
                iseditemodel = false;
            }
            //_readobj(false);
            // _readservice(false); 

            _apiget("/api/spider/serviceInfo?page=1&size=200", false, function (code, obj) {
                // $("[name=serviceId]").empty();
                if (code == 200) {
                    var datas = obj.items;
                    var htmlStr = "";
                    for (var k = 0; k < datas.length; k++) {
                        var item = datas[k];
                        if (item.fileModel == 1) {
                            htmlStr += '<option value="' + item.id + '">' + item.name + '(' + item.code + ')</option>';
                        }
                    }
                    $("[name=serviceId]").append(htmlStr);
                }
            });

            _readstore(false);

            if (iseditemodel) {

                $(".styleadd").hide();

                _loaditem(_id);
            } else {
                $(".styleedit").hide();

                var modelmap = funcreadmodel();
                var confightml = '';
                //渲染到UI
                if (modelmap != null) {
                    for (var ione of modelmap.values()) {
                        var item = {
                            prefixStr: '',
                            modelCode: ione.code,
                            branchName: '',
                            isEnable: false,
                            isEnableStr: ''
                        };
                        confightml += _buildtemplate($("#templatecloneconfigitem").html(), item);
                    }
                }
                $(".tableclone").find("tbody").html(confightml);

            }

        });

        function _loaditem(userid) {
            //读取角色列表
            _apiget("/api/spider/codeProject/" + userid + "/infoForUpdate", true, function (code, obj) {
                if (code == 200) {
                    _bindelement(obj);
                    //如果是后面添加的环境信息
                    var modelmap = funcreadmodel();
                    var confightml = '';
                    //渲染到UI
                    if (obj.configs) {

                        for (var i = 0; i < obj.configs.length; i++) {
                            var item = obj.configs[i];
                            if (modelmap != null) {
                                modelmap.delete(item.modelCode);
                            }
                            item.isEnableStr = "";
                            if (item.isEnable) {
                                item.isEnableStr = "checked";
                            }
                            confightml += _buildtemplate($("#templatecloneconfigitem").html(), item);
                        }
                    }
                    if (modelmap != null) {
                        for (var ione of modelmap.values()) {
                            var item = {
                                prefixStr: '',
                                modelCode: ione.code,
                                branchName: '',
                                isEnable: false,
                                isEnableStr: ''
                            };
                            confightml += _buildtemplate($("#templatecloneconfigitem").html(), item);
                        }
                    }

                    $(".tableclone").find("tbody").html(confightml);
                    //如果没有的，则添加默认的数据

                }
            });
        }

        function funcreadmodel() {
            //同步
            var models = null;
            _apiget("/api/spider/modelConfig?page=1&size=100", false, function (code, obj) {
                if (code == 200) {
                    // models = obj;
                    var objarr = new Map();
                    for (var k = 0; k < obj.items.length; k++) {
                        var item = obj.items[k];
                        objarr.set(item.code, item);
                    }
                    models = objarr;
                }
            })
            return models;
        }

        function _funcAdd() {

            var dataobj = $("#form-article-add").parseForm();

            //读取列表信息

            var configs = new Array();
            var trs = $(".tableclone").find('tr');
            for (var k = 0; k < trs.length; k++) {
                var one = trs[k];
                var item = {
                    prefixStr: $(one).find('.inputprefix').val(),
                    modelCode: $(one).find('.inputmodel').html(),
                    branchName: $(one).find('.inputbranch').val(),
                    isEnable: $(one).find('.inputenable').prop('checked'),
                };
                configs.push(item);
            }

            dataobj.configs = configs;

            if (iseditemodel) {
                _apipost("/api/spider/codeProject/updateItem", true, JSON.stringify(dataobj), function (code, obj) {
                    if (code == 200) {
                        layer.msg("更新成功", { time: 1500 }, function () {
                            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                            parent.layer.close(index);  // 关闭layer
                        });

                    }
                });
            } else {
                _apipost("/api/spider/codeProject/item", true, JSON.stringify(dataobj), function (code, obj) {
                    if (code == 200) {
                        layer.msg("添加成功");
                    }
                });
            }
        }
    </script>
    <!--/请在上方写此页面业务相关的脚本-->
</body>

</html>